import { Component, OnInit } from '@angular/core';
import { Router, ActivatedRoute } from '@angular/router';
import { HttpRouterService } from '../../service/http-router.service';
import { HttpService } from '../../service/http.service';
import { StorageService } from '../../service/storage.service';
import * as _ from 'underscore';

@Component({
  selector: 'app-personal',
  templateUrl: './personal.component.html',
  styleUrls: ['./personal.component.less']
})
export class PersonalComponent implements OnInit {

  public isLogIn = false;
  public showMessage = false;
  public user = [];
  public verification = '';
  public userImg = './assets/images/user.png';
  public balance = 0;

  constructor(
              private _http: HttpService,
              private _router: Router,
              private _activatedRoute: ActivatedRoute,
              private _storage: StorageService,
              private _httpRouter: HttpRouterService
  ) { }

  ngOnInit() {

    this.isLogIn = this._storage.getSession('token') ? true : false;
    if (this.isLogIn) {
      this.showMessage = true;
      this.user = JSON.parse(this._storage.getSession('user'));
      this.balance = this.user ? this.user['balance'] : 0;
      this.userImg = 'http://xdm.mengzhudai.com' + this.user['avatar'] || './assets/images/user.png';
    }

  }

  certification() {
    if (this.user['verification'] == 2 || this.user['verification'] == 3) {
      return;
    }
    this._router.navigate(['/attache/certification']);
  }

  logOut($event) {
    this._storage.removeSession('userId');
    this._storage.removeSession('user');
    this._storage.removeSession('token');
    this._storage.removeSession('preference');
    this._router.navigate(['/attache/login']);
  }


}
